﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Calculations;

namespace UI
{
	public partial class Form1 : Form, ICalculationView
	{
		public Form1() 
		{
			InitializeComponent();
		}

		#region ICalculationView Members


		public event EventHandler ValueUpdated;

		public int WoodRate
		{
			get
			{
				return Convert.ToInt32(wood.Value);
			}
			set
			{
				wood.ValueChanged -= new EventHandler(resource_ValueChanged);
				wood.Value = value;
				wood.ValueChanged += new EventHandler(resource_ValueChanged);
			}
		}

		void resource_ValueChanged(object sender, EventArgs e)
		{
			if (ValueUpdated != null)
			{
				ValueUpdated(this, EventArgs.Empty);
			}
		}

		public int ClayRate
		{
			get
			{
				return Convert.ToInt32(clay.Value);
			}
			set
			{
				clay.ValueChanged -= new EventHandler(resource_ValueChanged);
				clay.Value = value;
				clay.ValueChanged += new EventHandler(resource_ValueChanged);
			}
		}

		public int IronRate
		{
			get
			{
				return Convert.ToInt32(iron.Value);
			}
			set
			{
				iron.ValueChanged -= new EventHandler(resource_ValueChanged);
				iron.Value = value;
				iron.ValueChanged += new EventHandler(resource_ValueChanged);
			}
		}

		public int CropRate
		{
			get
			{
				return Convert.ToInt32(crop.Value);
			}
			set
			{
				crop.ValueChanged -= new EventHandler(resource_ValueChanged);
				crop.Value = value;
				crop.ValueChanged += new EventHandler(resource_ValueChanged);
			}
		}

		public int Wood
		{
			get
			{
				return Convert.ToInt32(StartingWood.Value);
			}
			set
			{
				StartingWood.ValueChanged -= new EventHandler(resource_ValueChanged);
				StartingWood.Value = value;
				StartingWood.ValueChanged += new EventHandler(resource_ValueChanged);
			}
		}

		public int Clay
		{
			get
			{
				return Convert.ToInt32(StartingClay.Value);
			}
			set
			{
				StartingClay.ValueChanged -= new EventHandler(resource_ValueChanged);
				StartingClay.Value = value;
				StartingClay.ValueChanged += new EventHandler(resource_ValueChanged);
			}
		}

		public int Iron
		{
			get
			{
				return Convert.ToInt32(StartingIron.Value);
			}
			set
			{
				StartingIron.ValueChanged -= new EventHandler(resource_ValueChanged);
				StartingIron.Value = value;
				StartingIron.ValueChanged += new EventHandler(resource_ValueChanged);
			}
		}

		public int Crop
		{
			get
			{
				return Convert.ToInt32(StartingCrop.Value);
			}
			set
			{
				StartingCrop.ValueChanged -= new EventHandler(resource_ValueChanged);
				StartingCrop.Value = value;
				StartingCrop.ValueChanged += new EventHandler(resource_ValueChanged);
			}
		}

		public int TimelineLength
		{
			get
			{
				return Convert.ToInt32(TimeLineInHours.Value);
			}
			set
			{
				TimeLineInHours.ValueChanged -= new EventHandler(resource_ValueChanged);
				TimeLineInHours.Value = value;
				TimeLineInHours.ValueChanged += new EventHandler(resource_ValueChanged);
			}
		}

		public IEnumerable<SnapShot> Timeline
		{
			set
            {
				timelineView.Items.Clear();
				DateTime time = DateTime.Now;
				int counter = 1;
				foreach (SnapShot snapShot in value)
				{
					timelineView.Items.Add(time.AddHours(counter).ToShortTimeString() + "\t" + snapShot.ToString());
					counter++;
				}
            }
		}

		#endregion

	}
}
